﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace BabyShop
{
    public partial class cart : System.Web.UI.Page
    {
        public DataTable dt;
        protected void Page_Load(object sender, EventArgs e)
        {
            dt = new DataTable();
            if (Request["id"] != "")
            {
                switch (Request["action"])
                {
                    case "add":
                        List<int> id_list = new List<int>();
                        if (Session["cart"] != null)
                        {
                            id_list = (List<int>)Session["cart"];
                        }
                        id_list.Add(int.Parse(Request["id"]));
                        Session["cart"] = id_list;
                        Response.Redirect("cart.aspx");
                        break;
                    case "remove":
                        if (Session["cart"] != null)
                        {
                            List<int> list = (List<int>)Session["cart"];
                            list.Remove(int.Parse(Request["id"]));
                            Session["cart"] = list;
                        }
                        Response.Redirect("cart.aspx");
                        break;
                    default:
                        break;
                }
            }
                if (Session["cart"] != null)
                {
                    List<int> id_list = (List<int>)Session["cart"];
                    string sql = "select products.*,brands.name as brand_name from products join brands on brands.id = products.brand_id where products.id in({0})";
                    string param = string.Join(",",id_list);
                    sql = string.Format(sql,param);
                    dt = DB_Provider.Read(sql);
                }
        }
    }
}